package com.zjw.zy.heart.control;


import com.zjw.zy.heart.bean.response.BaseResponse;
import com.zjw.zy.heart.domain.User;
import com.zjw.zy.heart.service.IUserService;
import com.zjw.zy.heart.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController()
@RequestMapping("/user")
public class UserControl {

    private IUserService service;

    @PostMapping("/register")
    public BaseResponse<Integer> applyRegister(@RequestBody User user) {
        Integer code = service.registerUser(user);
        return BaseResponse.ofSuccess(code);
    }

    @PostMapping("/lover")
    public BaseResponse<User> applyLover(@RequestBody User user) {
        user = service.queryUser(user.getUsername());
        User lover = null;
        if (user != null) {
            lover = service.queryUser(user.getLoveusername());
        }
        return BaseResponse.of(lover);
    }

    @Autowired
    public void setService(IUserService service) {
        this.service = service;
    }
}
